package com.example.layoutactivity

import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.widget.ArrayAdapter
import android.widget.Toast
import androidx.recyclerview.widget.LinearLayoutManager
import com.example.layoutactivity.adapter.FruitAdapter
import com.example.layoutactivity.pojo.Fruit
import kotlinx.android.synthetic.main.activity_main.*

class MainActivity : AppCompatActivity() {

//    private val data = listOf("Apple", "Banana", "Orange", "Watermelon", "Pear", "Grape", "Pineapple", "Strawberry", "Cherry", "Mango","Apple", "Banana", "Orange", "Watermelon", "Pear", "Grape", "Pineapple", "Strawberry", "Cherry", "Mango")
    private val data = ArrayList<Fruit>()


    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)
        initFruits()
//        listview.adapter = FruitAdapter(this,R.layout.fruit_item,data)
//        listview.setOnItemClickListener{
//            _,_,position,_-> val fruit = data[position]
//            Toast.makeText(this,fruit.name,Toast.LENGTH_SHORT).show()
//        }
        val layoutManager = LinearLayoutManager(this)
        layoutManager.orientation = LinearLayoutManager.HORIZONTAL
        recyclerView.layoutManager = layoutManager
        recyclerView.adapter = FruitAdapter(data)
    }

    private fun initFruits(){
        repeat(2){
            data.add(Fruit("Apple",R.drawable.apple_pic))
            data.add(Fruit("Orange",R.drawable.orange_pic))
            data.add(Fruit("Watermelon",R.drawable.watermelon_pic))
            data.add(Fruit("Pear",R.drawable.pear_pic))
            data.add(Fruit("Grape",R.drawable.grape_pic))
            data.add(Fruit("Pineapple",R.drawable.pineapple_pic))
            data.add(Fruit("Strawberry",R.drawable.strawberry_pic))
            data.add(Fruit("Cherry",R.drawable.cherry_pic))
            data.add(Fruit("Mango",R.drawable.mango_pic))
        }
    }
}